package cn.e3mall.service.impl;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.e3mall.mapper.TbItemMapper;
import cn.e3mall.pojo.TbItem;
import cn.e3mall.pojo.TbItemExample;
import cn.e3mall.pojo.TbItemExample.Criteria;
import cn.e3mall.service.TbItemService;
@Service
public class TbItemServiceImpl implements TbItemService {
	@Autowired
	private TbItemMapper mapper;
	private Logger logger= Logger.getLogger(TbItemServiceImpl.class);
	/**根据id查询单个商品信息
	 * <p>Description: </p>
	 * @param id  商品id主键
	 * @return  TbItem
	 * @see cn.e3mall.service.TbItemService#getTbItemById(long)
	 */
	@Override
	public TbItem getTbItemById(long id) {
		logger.info("进入查询方法getTbItemById");
		/**方法1**/
		//return mapper.selectById(id);
		/**方法2：利用逆向工程生成的example类来**/
		TbItemExample example = new TbItemExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdEqualTo(id);
		List<TbItem> list = mapper.selectByExample(example);
		if(list!=null && list.size()>0){
			logger.info("查询方法getTbItemById结束");
			return list.get(0);
		}else{
			logger.info("查询方法getTbItemById结束");
			return null;
		}
		
	}

}
